<?php 

namespace app\common\shop;

use think\Db;
use think\Model;
use traits\model\SoftDelete;


class HomeCateModel extends model {
    //use SoftDelete;//开启了软删除
    //protected  = 'del_time';
    // 完整数据表名
    protected $table = 'shop_home_cate';


    /**
     * [建表]
     * @return
     */
    public static function createTable(){
        return Db::query("CREATE TABLE If Not Exists `shop_home_cate` (
             `id` int(11) NOT NULL AUTO_INCREMENT,
             `title` varchar(255) NOT NULL COMMENT '分类标题',
             `img` text NOT NULL COMMENT '分类图片',
             `createtime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
             `updatetime` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '修改时间',
             PRIMARY KEY (`id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='首页分类设置'");
    }

    /**
     * [添加]
     * @return
     */
    public static function add($data){
        $data['createtime'] = time();
        $data['updatetime'] = time();
        return self::insertGetId($data);
    }

    /**
     * [修改]
     * @return
     */
    public static function edit($data,$id){
        $data['updatetime'] = time();
        return self::where('id',$id)->update($data);
    }


    /**
     * [获取审核状态]
     * @param
     * @return
     */
    public static function dispose($input,$id=''){
        $data = [
          'title'=>$input['title'],
          'img'=>serialize($input['path']),//图片$input['photo'],
        ];
        if($id){
            self::edit($data,$id);// 修改
        }else{
            $id = self::add($data);//添加
        }
        return $id;
    }
}
